﻿Imports System.Text
Imports VsSpeakerCompanion
Imports TwitterAPI

Namespace PeopleCounterWidget
	''' <summary>
	''' Keeps count of the total number of unique people participating in the audience
	''' </summary>
	Friend Class PeopleCounterWidget
		Implements IWidget
        Private WithEvents twitterService As TwitterService
		Private counter As PeopleCounter

		Public Sub New(ByVal twitterService As TwitterService)
            Me.twitterService = twitterService

            Me.counter = New PeopleCounter
		End Sub

        Private Sub twitterService_UsersCountChanged(ByVal source As Object, ByVal e As UsersCountEventArgs) Handles twitterService.UsersCountChanged
            ' update our UI to show the new people count
            counter.Dispatcher.Invoke(New Action(Sub() UpdateCounter(e.NewUsersCount)))
        End Sub

        Public Sub Reset() Implements IWidget.Reset
            ' reset the count of people back to zero
            counter.Dispatcher.Invoke(New Action(Sub() UpdateCounter(0)))
        End Sub

        Private Sub UpdateCounter(ByVal value As Integer)
            counter.Number = value
        End Sub

        Public ReadOnly Property VisualElement As System.Windows.UIElement Implements IWidget.VisualElement
            ' this is our UI
            Get
                Return counter
            End Get
        End Property
	End Class
End Namespace
